<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Vue测试</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <!-- <h1>点击次数:{{count}}</h1>
    <button type="button" @click="count+=1">点击</button>
    <button type="button" @click="clickEvent">点击2</button>

    <ul>
      <li v-for="item,index in list" :key="index" @click="clickEvent(index,item,$event)">{{index}}----{{item}}</li>
    </ul> -->
    <form action="" method="post">
      <input type="text" v-model="city" name="username" id="" value="">
      <input type="submit" @click.prevent=searchWeather() value="提交">
    </form>
    <div id="weather">
      <h1>{{weatherList.tmp}}</h1>
      <h3>{{weatherList.cond_txt}}----{{weatherList.wind_dir}}</h3>
    </div>
  </div>
  <script type="text/javascript">
    var app = new Vue({
      el: '#app',
      data: {
        count: 0,
        list: ['胡歌', '胡军', '胡冰卿'],
        city: '',
        weatherList: [],
      },
      methods: {
        clickEvent(index, value, event) {
          console.log(index, value);
          console.log(event); // 事件对象
        },
        async searchWeather() {
          console.log(this.city)
          let url = `https://free-api.heweather.net/s6/weather/now?location=${this.city}&key=3c497450d8e44c5280421ceaba1db581`;
          let res = await fetch(url);
          let result = await res.json();
          console.log(JSON.stringify(result.HeWeather6[0].now));
          this.weatherList = result.HeWeather6[0].now;
        }
      }
    })
  </script>
</body>

</html>